package com.cloud.business.controller.sys;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cloud.business.controller.BaseController;
import com.cloud.business.entity.sys.SysRegMapStruct;
import com.cloud.business.model.commonvm.DataDropDown;
import com.cloud.business.model.commonvm.DeletePost;
import com.cloud.business.model.commonvm.LngAndLat;
import com.cloud.business.model.commonvm.ResultMsg;
import com.cloud.business.model.sys.sysregmapstruct.MapStructDropDown;
import com.cloud.business.model.sys.sysregmapstruct.SysRegMapStructPost;
import com.cloud.business.model.sys.sysregmapstruct.SysRegMapStructQueryModel;
import com.cloud.business.service.sys.ISysRegMapStructService;
import com.cloud.core.common.HttpContentResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 地区架构表 API接口层
 * Copyright: Copyright (C) 2020 DLANGEL, Inc. All rights reserved.
 * Company: 大连安琪科技有限公司
 *
 * @author Rex
 * @since 2020-09-14 17:27:49
 */
@Api(tags = "地区架构表 模块")
@RestController
@RequestMapping("/api/sysRegMapStruct")
public class SysRegMapStructController extends BaseController {

    @Resource
    private ISysRegMapStructService sysRegMapStructService;


    //region 获取分页列表

    /**
     * 获取分页列表
     *
     * @param queryModel
     * @return
     */
    @ApiOperation(value = "获取分页列表")
    @PostMapping("/getListByPage")
    public HttpContentResult getListByPage(@RequestBody SysRegMapStructQueryModel queryModel) {
        ResultMsg msg = new ResultMsg();
        try {
            queryModel.setOperationId(getOperationId());
            IPage<SysRegMapStruct> page = new Page<>(queryModel.getPageNum(), queryModel.getRecordNum());
            sysRegMapStructService.getListByPage(queryModel, page, msg);
            return HttpContentResult.successResult(msg.getMsg(), page.getTotal(), page.getRecords());
        } catch (Exception ex) {
            return HttpContentResult.errorResult(ex.getMessage());
        }
    }
    //endregion

    //region 创建

    /**
     * 创建
     *
     * @param post
     * @return
     * @author Rex
     */
    @ApiOperation(value = "创建")
    @PostMapping("/create")
    public HttpContentResult create(@RequestBody SysRegMapStructPost post) {
        ResultMsg msg = new ResultMsg();
        try {
            post.setCreateUserId(getOperationId());
            Integer objectId = sysRegMapStructService.create(post, msg);
            return HttpContentResult.successResult(msg.getMsg(), 1L, objectId);
        } catch (Exception ex) {
            return HttpContentResult.errorResult(ex.getMessage());
        }
    }
    //endregion

    //region 更新

    /**
     * 更新
     *
     * @param post
     * @return
     * @author Rex
     */
    @ApiOperation(value = "更新")
    @PostMapping("/update")
    public HttpContentResult update(@RequestBody SysRegMapStructPost post) {
        ResultMsg msg = new ResultMsg();
        try {
            post.setModificationUserId(getOperationId());
            Integer objectId = sysRegMapStructService.update(post, msg);
            return HttpContentResult.successResult(msg.getMsg(), 1L, objectId);
        } catch (Exception ex) {
            return HttpContentResult.errorResult(ex.getMessage());
        }
    }
    //endregion

    //region 获取单条

    /**
     * 获取单条
     *
     * @param objectId
     * @return
     */
    @ApiOperation(value = "获取单条")
    @GetMapping("/getById")
    public HttpContentResult getById(Integer objectId) {
        ResultMsg msg = new ResultMsg();
        try {
            Integer operationId = getOperationId();
            SysRegMapStruct model = sysRegMapStructService.getById(operationId, objectId, msg);
            return HttpContentResult.successResult(msg.getMsg(), 1L, model);
        } catch (Exception ex) {
            return HttpContentResult.errorResult(ex.getMessage());
        }
    }
    //endregion

    //region 批量删除

    /**
     * 批量删除
     *
     * @param deletePost
     * @return
     * @author Rex
     */
    @ApiOperation(value = "批量删除")
    @PostMapping("/deleteByList")
    public HttpContentResult deleteByList(@RequestBody DeletePost deletePost) {
        ResultMsg msg = new ResultMsg();
        try {
            deletePost.setOperationId(getOperationId());
            Integer count = sysRegMapStructService.deleteByList(deletePost, msg);
            return HttpContentResult.successResult(msg.getMsg(), 1L, count);
        } catch (Exception ex) {
            return HttpContentResult.errorResult(ex.getMessage());
        }
    }
    //endregion

    //region 启用/停用

    /**
     * 启用/停用
     *
     * @param objectId
     * @param isEnable
     * @return
     */
    @ApiOperation(value = "启用/停用")
    @GetMapping("/enable")
    public HttpContentResult enable(Integer objectId, Integer isEnable) {
        ResultMsg msg = new ResultMsg();
        try {
            Integer operationId = getOperationId();
            sysRegMapStructService.enable(operationId, objectId, isEnable, msg);
            return HttpContentResult.successResult(msg.getMsg(), 1L, "");
        } catch (Exception ex) {
            return HttpContentResult.errorResult(ex.getMessage());
        }
    }
    //endregion

    //region 判断当前经纬度在哪个区域

    /**
     * 判断当前经纬度在哪个区域
     *
     * @param lngAndLat
     * @return
     */
    @ApiOperation(value = "判断当前经纬度在哪个区域")
    @PostMapping("/checkReg")
    public HttpContentResult checkReg(@RequestBody LngAndLat lngAndLat) {
        try {
//            Integer operationId = getOperationId();
            return sysRegMapStructService.checkReg(lngAndLat);
        } catch (Exception ex) {
            return HttpContentResult.errorResult(ex.getMessage());
        }
    }
    //endregion

    //region 获取下拉列表

    /**
     * 获取下拉列表
     *
     * @return
     */
    @ApiOperation(value = "获取下拉列表")
    @GetMapping("/getDropDownList")
    public HttpContentResult getDropDownList() {
        ResultMsg msg = new ResultMsg();
        try {
            Integer operationId = getOperationId();
            List<MapStructDropDown> dataDropDownList = sysRegMapStructService.getDropDownList(operationId, msg);
            return HttpContentResult.successResult(msg.getMsg(), 1L, dataDropDownList);
        } catch (Exception ex) {
            return HttpContentResult.errorResult(ex.getMessage());
        }
    }
    //endregion

    //region 更加用户获取下拉

    /**
     * 更加用户获取下拉
     *
     * @return
     */
    @ApiOperation(value = "更加用户获取下拉")
    @GetMapping("/getDropDownListByUserId")
    public HttpContentResult getDropDownListByUserId() {
        ResultMsg msg = new ResultMsg();
        try {
            Integer operationId = getOperationId();
            List<MapStructDropDown> dataDropDownList = sysRegMapStructService.getDropDownListByUserId(operationId, msg);
            return HttpContentResult.successResult(msg.getMsg(), 1L, dataDropDownList);
        } catch (Exception ex) {
            return HttpContentResult.errorResult(ex.getMessage());
        }
    }
    //endregion

}
